<?php
/**
 * Created by JetBrains PhpStorm.
 * User: MeRo
 * Date: 18.09.13
 * Time: 22:12
 * To change this template use File | Settings | File Templates.
 */

require_once 'templates/train/lib.php';
class getTemplateLandscape {

    protected $_echo = '';

    protected $_imgFiles = array();

    public function __construct() {
        $this
            ->_getImages()
            ->_generateHTML()
            ->_render()
        ;
        die();
    }

    protected function _addElement($element) {
        $this->_echo .= '
        ' . $element;

        return $this;
    }

    protected function _getImages() {
        $this->_imgFiles = array_diff(scandir('files/train/img/landscape'), array('.', '..'));
        return $this;
    }

    protected function _generateHTML() {
        $count = count($this->_imgFiles);
        $i = 0;
        foreach ($this->_imgFiles as $img) {
            $last = $count == ($i++ + 1) ? 'last' : '';
            $this->_addElement('<div class="landscapeTemplage brickTemplate pointer ' . $last . '">
                <img src="files/train/img/landscape/' . $img . '" alt="' . $img . '">
            </div>');
        }
        file_put_contents('bla.txt', 'bla.txt');
        return $this;
    }

    protected function _render() {
        echo json_encode($this->_echo);

        return $this;
    }
}

new getTemplateLandscape;
